package znbkTopicType.content;

import android.content.Context;
import android.os.Handler;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.lancooznbk.R;

import org.apache.commons.lang3.StringEscapeUtils;

import lancooControl.Control;
import lancooControl.CustomAnswerChoiceView;
import znbkTopicType.WrapBaseAdapter;
import znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;

import static android.view.View.GONE;
import static znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity.mEntityCtfd;
import static znbkTestPaperLstjt.activity.HistoryRecommendQuesPaperActivity.mEntityLstjt;
import static znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity.mEntityNtxl;
import static znbkTestPaperRdqh.activity.WeekAscensionPaperActivity.mEntityRdqh;
import static znbkTestPaperXtfx.activity.SystemReviewPaperActivity.mEntityXtfx;

/**
 * Created by Administrator on 2017/8/17/017.
 */

public class ZnbkContentDxtAdapter extends WrapBaseAdapter{

    private LayoutInflater mInflater;
    //当前试题数量
    private int ItemCount;
    //当前试题在当前试题的ID
    private int PaperID;
    private Context mContext;
    private int ModelFrom;//试卷来源

    private int tvBlack;
    private int tvBlue;
    private int tvWhite;
    private int tvGreen;
    private int tvRed;
    private int btnWhite;
    private int btnBlue;
    private int btnGreen;
    private int btnRed;

    /*
    * 获取小题选项信息
    * */
    private int status;//试卷的作答状态
    private double score;//大题总分
    private int sumOption;//选项的个数
    private String stuAnswer;//用户答案
    private String answer;//正确答案
    private String subChildAsk;//小题题目信息
    private String analysis;//答案解析
    private String typeName;

    private String[] optionIndex;//选项号所对应的文字
    private String[] option;//选项内容对应的文字

    private View mView;

    private ViewHolder holder = null;
    private class ViewHolder{
       /* TextView TvTypeName;//题目类型
        ClickImageView mCivAccessToCounselling;//进入辅导
        ClickImageView mCivNotes;
        ClickImageView mCivKnowledgePoint;*/
        WebView mWvTheme;//大题文本题干
        LinearLayout LayoutOptions;//选项显示区
        LinearLayout LayoutCheckAnalysis;//答案显示区
        LinearLayout LayoutStuAnswer;
        LinearLayout LayoutAnswer;
        LinearLayout LayoutAnalysis;
        TextView TvAnswer;//正确答案
        TextView TvStuAnswer;//学生答案
        TextView TvScore;//得分
        TextView TvAnalysis;//解析
        LinearLayout LayoutStuAssess;//自评显示区

        private ViewHolder(View convertView) {
            mView = convertView;
//            TvTypeName = (TextView) convertView.findViewById(R.id.tv_typeName);
//            mCivAccessToCounselling = (ClickImageView) convertView.findViewById(R.id.civ_accessToCounselling);
//            mCivNotes = (ClickImageView) convertView.findViewById(R.id.civ_notes);
//            mCivKnowledgePoint = (ClickImageView) convertView.findViewById(R.id.civ_knowledgePoint);
            mWvTheme = (WebView) convertView.findViewById(R.id.wv_theme);
            LayoutOptions = (LinearLayout) convertView.findViewById(R.id.layout_options);
            LayoutCheckAnalysis= (LinearLayout) convertView.findViewById(R.id.layout_checkAnalysis);
            LayoutStuAnswer = (LinearLayout) convertView.findViewById(R.id.layout_stuAnswer);
            LayoutAnswer = (LinearLayout) convertView.findViewById(R.id.layout_answer);
            LayoutAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_analysis);
            TvAnswer = (TextView) convertView.findViewById(R.id.tv_answer);
            TvStuAnswer = (TextView) convertView.findViewById(R.id.tv_stuAnswer);
            TvScore = (TextView) convertView.findViewById(R.id.tv_score);
            TvAnalysis = (TextView) convertView.findViewById(R.id.tv_analysis);
            LayoutStuAssess = (LinearLayout) convertView.findViewById(R.id.layout_stuAssess);
        }
    }

    private CustomAnswerChoiceView[] ChoiceAnswer;//选项信息


    public ZnbkContentDxtAdapter(Context context, int itemCount, int paperID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.ItemCount = itemCount;
        this.PaperID = paperID;
        this.ModelFrom = modelFrom;

        tvBlack = mContext.getResources().getColor(R.color.black);
        tvBlue = mContext.getResources().getColor(R.color.blue);
        tvWhite = mContext.getResources().getColor(R.color.white);
        tvGreen = mContext.getResources().getColor(R.color.green);
        tvRed = mContext.getResources().getColor(R.color.red);

        btnWhite = R.mipmap.option_normal;
        btnBlue = R.mipmap.option_select;
        btnGreen = R.mipmap.option_right;
        btnRed = R.mipmap.option_wrong;
    }

    @Override
    public int getCount() {
        return ItemCount;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.znbk_adapter_content_dxt_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        /*
        * 获取试题相关信息
        * */
        getQuesInfor();

        /*
        * 展示作答区内容及实现作答流程
        * */
        showQuesInfor();

        /*
        * 已提交状态下，初始化答案解析
        * */
        showAnalysis();


        return convertView;
    }

    /*
    * 获取试题相关信息
    * */
    private void getQuesInfor(){

        if(ModelFrom == ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            //试卷的作答状态
            status = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            //大题总分
            score = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getDetail().get(PaperID).getScore();
            //获取大题题干内容
            subChildAsk = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            //选项个数
            sumOption = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
            typeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTypeName();


        }else if(ModelFrom == ZnbkPaperDef.FROM_WEEK_ASCENSION){
            //试卷的作答状态
            status = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            //大题总分
            score = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getDetail().get(PaperID).getScore();
            //获取大题题干内容
            subChildAsk = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            //选项个数
            sumOption = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
            typeName = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTypeName();


        }else if(ModelFrom== ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS) {

            //试卷的作答状态
            status = mEntityNtxl.getAnswerState();
            //获取大题题干内容
            subChildAsk = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            //选项个数
            sumOption = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
            typeName = mEntityNtxl.getTKQue().getTypeName();
//            correctRate = mEntityNtxl.getCorrectRate();
        }else if(ModelFrom == ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
            /*
            * 当前推荐题作答状态
            * */
            status = mEntityCtfd.getRecQues().get(0).getAnswerState();
            //试卷的作答状态
            int anotherPaperID = -1;
            if (PaperID == 0) {
                anotherPaperID = PaperID;
                //获取小题题干内容
                subChildAsk = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildAsk();
                //选项个数
                sumOption = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildOptionList().size();
                //用户答案
                stuAnswer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildStuAnswer();
                //正确答案
                answer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildAnswer();
                //答案解析
                analysis = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildAnalyze();
                //获取选项题号及选项内容
                optionIndex = new String[sumOption];
                option = new String[sumOption];
                for (int i = 0; i < sumOption; i++) {
                    optionIndex[i] = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                    option[i] = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                }
                typeName = mEntityCtfd.getPrimitiveQues().getTKQue().getTypeName();
            } else {

                if(PaperID==1){
                     anotherPaperID = PaperID-1;
                    if (mEntityCtfd.getClassicalQues()!= null) {
                        //获取小题题干内容
                        subChildAsk = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildAsk();
                        //选项个数
                        sumOption = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildOptionList().size();
                        //用户答案
                        stuAnswer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildStuAnswer();
                        //正确答案
                        answer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildAnswer();
                        //答案解析
                        analysis = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildAnalyze();
                        //获取选项题号及选项内容
                        optionIndex = new String[sumOption];
                        option = new String[sumOption];
                        for (int i = 0; i < sumOption; i++) {
                            optionIndex[i] = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                            option[i] = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                        }
                        typeName = mEntityCtfd.getClassicalQues().getTKQue().getTypeName();
                    }else{
                        //获取小题题干内容
                        subChildAsk = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                        //选项个数
                        sumOption = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().size();
                        //用户答案
                        stuAnswer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                        //正确答案
                        answer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                        //答案解析
                        analysis = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                        //获取选项题号及选项内容
                        optionIndex = new String[sumOption];
                        option = new String[sumOption];
                        for (int i = 0; i < sumOption; i++) {
                            optionIndex[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                            option[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                        }
                        typeName = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTypeName();
                    }
                }else{
                    if (mEntityCtfd.getClassicalQues()!= null) {
                        anotherPaperID = PaperID - 2;
                    } else {
                        anotherPaperID = PaperID - 1;
                    }
                    //获取小题题干内容
                    subChildAsk = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                    //选项个数
                    sumOption = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().size();
                    //用户答案
                    stuAnswer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                    //正确答案
                    answer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                    //答案解析
                    analysis = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                    //获取选项题号及选项内容
                    optionIndex = new String[sumOption];
                    option = new String[sumOption];
                    for (int i = 0; i < sumOption; i++) {
                        optionIndex[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                        option[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                    }
                    typeName = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTypeName();
                }
            }
        }else if(ModelFrom == ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
            //试卷的作答状态
            status = 3;
            //获取大题题干内容
            subChildAsk = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            //选项个数
            sumOption = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
            typeName = mEntityLstjt.get(PaperID).getTKQue().getTypeName();
//            correctRate = mEntityLstjt.get(PaperID).getCorrectRate();
        }
    }


    /*
    * 展示试题信息
    * */
    Handler htmlHandlerItemContent = new Handler();
    private void showQuesInfor(){

        /*
        * 显示题目题干
        * */

        holder.mWvTheme.loadDataWithBaseURL("about:blank", subChildAsk, "text/html", "utf-8", null);
        holder.mWvTheme.getSettings().setDefaultFontSize(18);
        holder.mWvTheme.setFocusable(false);

//        itemContent = StringEscapeUtils.unescapeXml(itemContent);
//        new Thread(new Runnable()
//        {
//            @Override
//            public void run()
//            {
//                final Spanned tvItemContent = Html.fromHtml(itemContent, Control.imgGetter,null);
//                htmlHandlerItemContent.post(new Runnable()
//                {
//                    @Override
//                    public void run()
//                    {
//                        holder.TvItemContent.setText(tvItemContent);
//                        holder.TvItemContent.setTextSize(18);
//                    }
//                });
//            }
//        }).start();


        /*
        * 显示选项内容
        * */
        ChoiceAnswer = new CustomAnswerChoiceView[sumOption];
        for(int i =0;i<sumOption;i++){
            ChoiceAnswer[i] = new CustomAnswerChoiceView(mContext);
            ChoiceAnswer[i].setAnswerChoice(optionIndex[i],tvBlack,btnWhite,option[i],tvBlack);

            final int finalI = i;
            ChoiceAnswer[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (status==2||status==3) {
                        return;
                    } else {
                        if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
                            int anotherPaperID = -1;
                            if(PaperID==0){
                                return;
                            }else if(PaperID==1){
                                anotherPaperID=PaperID-1;
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    return;
                                }else{
                                    if(status==2||status==3){
                                        return;
                                    }else{
                                        stuAnswer=mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(anotherPaperID).getSubChildList().get(0).getSubChildStuAnswer();
                                        mEntityCtfd.getRecQues().get(0).setAnswerState(1);
                                        WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                        mEntityCtfd.setStepFlag(2);
                                    }
                                }
                            }else {
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    anotherPaperID = PaperID-2;
                                }else{
                                    anotherPaperID = PaperID-1;
                                }
                                mEntityCtfd.getRecQues().get(anotherPaperID).setAnswerState(1);
                                WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                mEntityCtfd.setStepFlag(2);
                            }


                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {

                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    if(mEntityCtfd.getClassicalQues()==null) {
                                        RecPaperID = PaperID - 1;
                                    }else{
                                        RecPaperID = PaperID - 2;
                                    }
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);

                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom== ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
                               return;
                        }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
                              SystemReviewPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
                            mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                            WeekAscensionPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS) {
//                            ZnbkPaperNtxlInfor.AnswerState = 1;
                            mEntityNtxl.setAnswerState(1);
                            TrainingDifficultProblemsPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }

                    }
                }
            });

            ChoiceAnswer[i].BtnChoice.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (status==2||status==3) {
                        return;
                    } else {
                        if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
                            int anotherPaperID = -1;
                            if(PaperID==0){
                                return;
                            }else if(PaperID==1){
                                anotherPaperID=PaperID-1;
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    return;
                                }else{
                                    if(status==2||status==3){
                                        return;
                                    }else{
                                        mEntityCtfd.getRecQues().get(0).setAnswerState(1);
                                        WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                        mEntityCtfd.setStepFlag(2);
                                    }
                                }
                            }else {
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    anotherPaperID = PaperID-2;
                                }else{
                                    anotherPaperID = PaperID-1;
                                }
                                if(status==2||status==3){
                                    return;
                                }else{
                                    mEntityCtfd.getRecQues().get(anotherPaperID).setAnswerState(1);
                                    WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                    mEntityCtfd.setStepFlag(2);
                                }
                            }

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    if(mEntityCtfd.getClassicalQues()==null) {
                                        RecPaperID = PaperID - 1;
                                    }else{
                                        RecPaperID = PaperID - 2;
                                    }
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom== ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
                            return;
                        }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
                            SystemReviewPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }
                        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
                            mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                            WeekAscensionPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }
                        }else if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS) {
//                            stuAnswer = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
//                            ZnbkPaperNtxlInfor.AnswerState = 1;
                            mEntityNtxl.setAnswerState(1);
                            TrainingDifficultProblemsPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    int RecPaperID = -1;
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }
                        }

                    }
                }
            });

            holder.LayoutOptions.addView(ChoiceAnswer[i]);

        }

        if (status==2||status==3) {
            //已提交
            int currentOption = -1;
            int currentTrueOption = -1;
            if(!stuAnswer.equals("")){
                currentOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                if (stuAnswer.equals(answer)) {
                    for (int k = 0; k < sumOption; k++) {
                        if (currentOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                        }
                    }
                } else if (!stuAnswer.equals(answer)) {
                    for (int k = 0; k < sumOption; k++) {

                        if (currentOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnRed,option[k],tvRed);
                        }
                        if(currentTrueOption == k){
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                        }
                    }
                }
            }
             /*
            * 学生答案为空
            * */
            else{
                currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                for (int k = 0; k < sumOption; k++) {

                    if(currentTrueOption == k){
                        ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                    }
                }
            }

        }else{
            //未提交

            if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){
                int anotherPaperID = -1;
                if(PaperID==0){
                    int currentOption = -1;
                    int currentTrueOption = -1;
                    if(!stuAnswer.equals("")){
                        currentOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                        currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                        if (stuAnswer.equals(answer)) {
                            for (int k = 0; k < sumOption; k++) {
                                if (currentOption == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                                }
                            }
                        } else if (!stuAnswer.equals(answer)) {
                            for (int k = 0; k < sumOption; k++) {

                                if (currentOption == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnRed,option[k],tvRed);
                                }
                                if(currentTrueOption == k){
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                                }
                            }
                        }
                    }else{
                        currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                        for (int k = 0; k < sumOption; k++) {
                            if(currentTrueOption == k){
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                            }
                        }
                    }

                }else if(PaperID==1){
                    anotherPaperID = PaperID-1;
                    if(mEntityCtfd.getClassicalQues()!=null){
                        int currentTrueOption = -1;
                        currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                        for (int k = 0; k < sumOption; k++) {
                            if(currentTrueOption == k){
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                            }
                        }
                    }else{
                        if (!stuAnswer.equals("")) {

                            int trueOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                            Log.e("==AAA=11=", "======trueOption======" + trueOption);

                            for (int k = 0; k < sumOption; k++) {
                                if (trueOption == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                }
                            }

                        }
                    }
                }else{
                    if (!stuAnswer.equals("")) {

                        int trueOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                        Log.e("==AAA=11=", "======trueOption======" + trueOption);

                        for (int k = 0; k < sumOption; k++) {
                            if (trueOption == k) {
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                            }
                        }

                    }
                }
            }else{
                /*非错题辅导*/
                if (!stuAnswer.equals("")) {

                    int trueOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                    Log.e("==AAA=11=", "======trueOption======" + trueOption);

                    for (int k = 0; k < sumOption; k++) {
                        if (trueOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                        }
                    }

                }
            }
        }

    }



    /*
    * 已提交状态试题分析部分内容展示
    * */
    private void showAnalysis() {

            /*
            * 难题训练/系统复习/弱点强化
            * */
            if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS||
                    ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW||
                    ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION||
                    ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
                if(status==2||status==3) {

                    /*
                    * 显示题目回看解析内容
                    * */
                        holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                    /*
                    * 显示我的答案
                    * */
                        holder.LayoutStuAnswer.setVisibility(View.VISIBLE);
                        if (stuAnswer.equals("")) {
                            holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                        } else {
                            holder.TvStuAnswer.setText(stuAnswer);
                        }
                        if (stuAnswer.equals(answer)) {
                            holder.TvStuAnswer.setTextColor(tvGreen);
                        } else {
                            holder.TvStuAnswer.setTextColor(tvRed);
                        }
                    /*
                    * 显示参考答案
                    * */
                        holder.LayoutAnswer.setVisibility(View.VISIBLE);
                        holder.TvAnswer.setText(answer);
                        holder.TvAnswer.setTextColor(tvGreen);
                    /*
                    * 显示答案解析
                    * */
                        holder.LayoutAnalysis.setVisibility(View.VISIBLE);
                        if (analysis.equals("")) {
                            holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                        } else {
                            holder.TvAnalysis.setText(analysis);
                        }
                        holder.TvAnalysis.setTextColor(tvBlack);

                }else{
                     /*
                    * 隐藏题目回看解析内容
                    * */
                    holder.LayoutCheckAnalysis.setVisibility(View.GONE);
                }

            }
            /*
            * 错题辅导
            * */
            else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
                Log.e("==PaperID==", "" + PaperID);
                if (PaperID == 0) {

                    //显示题目回看解析内容
                    holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                    holder.LayoutStuAnswer.setVisibility(View.VISIBLE);
                    //我的答案
                    if (stuAnswer.equals(answer)) {
                        holder.TvStuAnswer.setTextColor(tvGreen);
                    } else {
                        holder.TvStuAnswer.setTextColor(tvRed);
                    }
                    if (!stuAnswer.equals("")) {
                        holder.TvStuAnswer.setText(stuAnswer);
                    } else {
                        holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                    }
                    //显示参考答案
                    holder.TvAnswer.setText(answer);
                    holder.TvAnswer.setTextColor(tvGreen);
                    //显示答案解析
                    if (!analysis.equals("")) {
                        holder.TvAnalysis.setText(analysis);
                    } else {
                        holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                    }
                    holder.TvAnalysis.setTextColor(tvBlack);

                } else if (PaperID == 1) {

                    if (mEntityCtfd.getClassicalQues() != null) {
                        //显示题目回看解析内容
                        holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                        holder.LayoutStuAnswer.setVisibility(GONE);
                        //显示参考答案
                        holder.TvAnswer.setText(Html.fromHtml(answer));
                        holder.TvAnswer.setTextColor(tvGreen);
                        //显示答案解析
                        if (!analysis.equals("")) {
                            holder.TvAnalysis.setText(analysis);
                        } else {
                            holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                        }

                    } else {
                        if (status == 2 || status == 3) {
                            holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                            holder.LayoutStuAnswer.setVisibility(View.VISIBLE);
                            /*
                            * 显示我的答案
                            * */
                            if (!stuAnswer.equals("")) {
                                holder.TvStuAnswer.setText(stuAnswer);
                                if (stuAnswer.equals(answer)) {
                                    holder.TvStuAnswer.setTextColor(tvGreen);
                                } else {
                                    holder.TvStuAnswer.setTextColor(tvRed);
                                }
                            } else {
                                holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                                holder.TvStuAnswer.setTextColor(tvRed);
                            }
                            /**
                             * 显示参考答案
                             * */
                            holder.TvAnswer.setText(Html.fromHtml(answer));
                            holder.TvAnswer.setTextColor(tvGreen);
                            /**
                             * 显示解析
                             * */
                            if (!analysis.equals("")) {
                                holder.TvAnalysis.setText(analysis);
                            } else {
                                holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                            }
                        } else {
                            holder.LayoutCheckAnalysis.setVisibility(GONE);
                        }
                    }
                } else {
                    if (status == 2 || status == 3) {
                        holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                        holder.LayoutStuAnswer.setVisibility(View.VISIBLE);
                            /*
                            * 显示我的答案
                            * */
                        if (!stuAnswer.equals("")) {
                            holder.TvStuAnswer.setText(stuAnswer);
                            if (stuAnswer.equals(answer)) {
                                holder.TvStuAnswer.setTextColor(tvGreen);
                            } else {
                                holder.TvStuAnswer.setTextColor(tvRed);
                            }
                        } else {
                            holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                            holder.TvStuAnswer.setTextColor(tvRed);
                        }
                        /**
                         * 显示参考答案
                         * */
                        holder.TvAnswer.setText(Html.fromHtml(answer));
                        holder.TvAnswer.setTextColor(tvGreen);
                        /**
                         * 显示解析
                         * */
                        if (!analysis.equals("")) {
                            holder.TvAnalysis.setText(analysis);
                        } else {
                            holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                        }
                    } else {
                        holder.LayoutCheckAnalysis.setVisibility(View.GONE);
                    }
                }
            }


    }

    /*
    * 写入作答信息
    * */
    private void setStuAnswerInfor(String strStuAnswer,int recPaperID){
        if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){
            mEntityNtxl.getTKQue().getChildList().get(PaperID).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){
           mEntityCtfd.getRecQues().get(recPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
        }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
        }
    }
}